﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using Indeco.G24.Entities;
using Indeco.G24.Data;

#endregion

namespace Indeco.G24.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="NhaCungCapNganhNgheKinhDoanhProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class NhaCungCapNganhNgheKinhDoanhProviderBaseCore : EntityProviderBase<Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh, Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanhKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanhKey key)
		{
			return Delete(transactionManager, key.IDNhaCungCap, key.IDNganhNgheKinhDoanh);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="iDNhaCungCap">. Primary Key.</param>
		/// <param name="iDNganhNgheKinhDoanh">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Guid iDNhaCungCap, System.Guid iDNganhNgheKinhDoanh)
		{
			return Delete(null, iDNhaCungCap, iDNganhNgheKinhDoanh);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNhaCungCap">. Primary Key.</param>
		/// <param name="iDNganhNgheKinhDoanh">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Guid iDNhaCungCap, System.Guid iDNganhNgheKinhDoanh);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh key.
		///		FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh Description: 
		/// </summary>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNganhNgheKinhDoanh(System.Guid iDNganhNgheKinhDoanh)
		{
			int count = -1;
			return GetByIDNganhNgheKinhDoanh(iDNganhNgheKinhDoanh, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh key.
		///		FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		/// <remarks></remarks>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNganhNgheKinhDoanh(TransactionManager transactionManager, System.Guid iDNganhNgheKinhDoanh)
		{
			int count = -1;
			return GetByIDNganhNgheKinhDoanh(transactionManager, iDNganhNgheKinhDoanh, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh key.
		///		FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNganhNgheKinhDoanh(TransactionManager transactionManager, System.Guid iDNganhNgheKinhDoanh, int start, int pageLength)
		{
			int count = -1;
			return GetByIDNganhNgheKinhDoanh(transactionManager, iDNganhNgheKinhDoanh, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh key.
		///		fKTbNhaCungCapNganhNgheKinhDoanhTbNganhNgheKinhDoanh Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNganhNgheKinhDoanh(System.Guid iDNganhNgheKinhDoanh, int start, int pageLength)
		{
			int count =  -1;
			return GetByIDNganhNgheKinhDoanh(null, iDNganhNgheKinhDoanh, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh key.
		///		fKTbNhaCungCapNganhNgheKinhDoanhTbNganhNgheKinhDoanh Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNganhNgheKinhDoanh(System.Guid iDNganhNgheKinhDoanh, int start, int pageLength,out int count)
		{
			return GetByIDNganhNgheKinhDoanh(null, iDNganhNgheKinhDoanh, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh key.
		///		FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NganhNgheKinhDoanh Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public abstract Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNganhNgheKinhDoanh(TransactionManager transactionManager, System.Guid iDNganhNgheKinhDoanh, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap key.
		///		FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap Description: 
		/// </summary>
		/// <param name="iDNhaCungCap"></param>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNhaCungCap(System.Guid iDNhaCungCap)
		{
			int count = -1;
			return GetByIDNhaCungCap(iDNhaCungCap, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap key.
		///		FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNhaCungCap"></param>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		/// <remarks></remarks>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNhaCungCap(TransactionManager transactionManager, System.Guid iDNhaCungCap)
		{
			int count = -1;
			return GetByIDNhaCungCap(transactionManager, iDNhaCungCap, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap key.
		///		FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNhaCungCap"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNhaCungCap(TransactionManager transactionManager, System.Guid iDNhaCungCap, int start, int pageLength)
		{
			int count = -1;
			return GetByIDNhaCungCap(transactionManager, iDNhaCungCap, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap key.
		///		fKTbNhaCungCapNganhNgheKinhDoanhTbNhaCungCap Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="iDNhaCungCap"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNhaCungCap(System.Guid iDNhaCungCap, int start, int pageLength)
		{
			int count =  -1;
			return GetByIDNhaCungCap(null, iDNhaCungCap, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap key.
		///		fKTbNhaCungCapNganhNgheKinhDoanhTbNhaCungCap Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="iDNhaCungCap"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNhaCungCap(System.Guid iDNhaCungCap, int start, int pageLength,out int count)
		{
			return GetByIDNhaCungCap(null, iDNhaCungCap, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap key.
		///		FK_tb_NhaCungCapNganhNgheKinhDoanh_tb_NhaCungCap Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNhaCungCap"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh objects.</returns>
		public abstract Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> GetByIDNhaCungCap(TransactionManager transactionManager, System.Guid iDNhaCungCap, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh Get(TransactionManager transactionManager, Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanhKey key, int start, int pageLength)
		{
			return GetByIDNhaCungCapIDNganhNgheKinhDoanh(transactionManager, key.IDNhaCungCap, key.IDNganhNgheKinhDoanh, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_tb_NhaCungCapNganhNgheKinhDoanh index.
		/// </summary>
		/// <param name="iDNhaCungCap"></param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> class.</returns>
		public Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh GetByIDNhaCungCapIDNganhNgheKinhDoanh(System.Guid iDNhaCungCap, System.Guid iDNganhNgheKinhDoanh)
		{
			int count = -1;
			return GetByIDNhaCungCapIDNganhNgheKinhDoanh(null,iDNhaCungCap, iDNganhNgheKinhDoanh, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_NhaCungCapNganhNgheKinhDoanh index.
		/// </summary>
		/// <param name="iDNhaCungCap"></param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> class.</returns>
		public Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh GetByIDNhaCungCapIDNganhNgheKinhDoanh(System.Guid iDNhaCungCap, System.Guid iDNganhNgheKinhDoanh, int start, int pageLength)
		{
			int count = -1;
			return GetByIDNhaCungCapIDNganhNgheKinhDoanh(null, iDNhaCungCap, iDNganhNgheKinhDoanh, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_NhaCungCapNganhNgheKinhDoanh index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNhaCungCap"></param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> class.</returns>
		public Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh GetByIDNhaCungCapIDNganhNgheKinhDoanh(TransactionManager transactionManager, System.Guid iDNhaCungCap, System.Guid iDNganhNgheKinhDoanh)
		{
			int count = -1;
			return GetByIDNhaCungCapIDNganhNgheKinhDoanh(transactionManager, iDNhaCungCap, iDNganhNgheKinhDoanh, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_NhaCungCapNganhNgheKinhDoanh index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNhaCungCap"></param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> class.</returns>
		public Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh GetByIDNhaCungCapIDNganhNgheKinhDoanh(TransactionManager transactionManager, System.Guid iDNhaCungCap, System.Guid iDNganhNgheKinhDoanh, int start, int pageLength)
		{
			int count = -1;
			return GetByIDNhaCungCapIDNganhNgheKinhDoanh(transactionManager, iDNhaCungCap, iDNganhNgheKinhDoanh, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_NhaCungCapNganhNgheKinhDoanh index.
		/// </summary>
		/// <param name="iDNhaCungCap"></param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> class.</returns>
		public Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh GetByIDNhaCungCapIDNganhNgheKinhDoanh(System.Guid iDNhaCungCap, System.Guid iDNganhNgheKinhDoanh, int start, int pageLength, out int count)
		{
			return GetByIDNhaCungCapIDNganhNgheKinhDoanh(null, iDNhaCungCap, iDNganhNgheKinhDoanh, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_NhaCungCapNganhNgheKinhDoanh index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDNhaCungCap"></param>
		/// <param name="iDNganhNgheKinhDoanh"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> class.</returns>
		public abstract Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh GetByIDNhaCungCapIDNganhNgheKinhDoanh(TransactionManager transactionManager, System.Guid iDNhaCungCap, System.Guid iDNganhNgheKinhDoanh, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a Indeco.G24.Entities.TList&lt;NhaCungCapNganhNgheKinhDoanh&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="Indeco.G24.Entities.TList&lt;NhaCungCapNganhNgheKinhDoanh&gt;"/></returns>
		public static Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> Fill(IDataReader reader, Indeco.G24.Entities.TList<NhaCungCapNganhNgheKinhDoanh> rows, int start, int pageLength)
		{
		// advance to the starting row
		for (int i = 0; i < start; i++)
		{
			if (!reader.Read())
			return rows; // not enough rows, just return
		}
		for (int i = 0; i < pageLength; i++)
		{
			if (!reader.Read())
			break; // we are done
			string key = null;
			
			Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh c = null;
			if (DataRepository.Provider.UseEntityFactory)
			{
			key = new System.Text.StringBuilder("NhaCungCapNganhNgheKinhDoanh")
			.Append("|").Append((reader.IsDBNull(((int)Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanhColumn.IDNhaCungCap - 1))?Guid.Empty:(System.Guid)reader[((int)Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanhColumn.IDNhaCungCap - 1)]).ToString())
			.Append("|").Append((reader.IsDBNull(((int)Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanhColumn.IDNganhNgheKinhDoanh - 1))?Guid.Empty:(System.Guid)reader[((int)Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanhColumn.IDNganhNgheKinhDoanh - 1)]).ToString()).ToString();
			c = EntityManager.LocateOrCreate<NhaCungCapNganhNgheKinhDoanh>(
			key.ToString(), // EntityTrackingKey
			"NhaCungCapNganhNgheKinhDoanh",  //Creational Type
			DataRepository.Provider.EntityCreationalFactoryType,  //Factory used to create entity
			DataRepository.Provider.EnableEntityTracking); // Track this entity?
			}
			else
			{
			c = new Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh();
			}
			
			if (!DataRepository.Provider.EnableEntityTracking ||
			c.EntityState == EntityState.Added ||
			(DataRepository.Provider.EnableEntityTracking &&
			((DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
			(DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.DiscardChanges && (c.EntityState == EntityState.Unchanged ||
								c.EntityState == EntityState.Changed)))))
						{
			c.SuppressEntityEvents = true;
			c.IDNhaCungCap = (System.Guid)reader["ID_NhaCungCap"];
			c.OriginalIDNhaCungCap = c.IDNhaCungCap;
			c.IDNganhNgheKinhDoanh = (System.Guid)reader["ID_NganhNgheKinhDoanh"];
			c.OriginalIDNganhNgheKinhDoanh = c.IDNganhNgheKinhDoanh;
			c.EntityTrackingKey = key;
			c.AcceptChanges();
			c.SuppressEntityEvents = false;
			}
			rows.Add(c);
		}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh entity)
		{
			if (!reader.Read()) return;
			
			entity.IDNhaCungCap = (System.Guid)reader["ID_NhaCungCap"];
			entity.OriginalIDNhaCungCap = (System.Guid)reader["ID_NhaCungCap"];
			entity.IDNganhNgheKinhDoanh = (System.Guid)reader["ID_NganhNgheKinhDoanh"];
			entity.OriginalIDNganhNgheKinhDoanh = (System.Guid)reader["ID_NganhNgheKinhDoanh"];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDNhaCungCap = (System.Guid)dataRow["ID_NhaCungCap"];
			entity.OriginalIDNhaCungCap = (System.Guid)dataRow["ID_NhaCungCap"];
			entity.IDNganhNgheKinhDoanh = (System.Guid)dataRow["ID_NganhNgheKinhDoanh"];
			entity.OriginalIDNganhNgheKinhDoanh = (System.Guid)dataRow["ID_NganhNgheKinhDoanh"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		internal override void DeepLoad(TransactionManager transactionManager, Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region IDNganhNgheKinhDoanhSource	
			if (CanDeepLoad(entity, "NganhNgheKinhDoanh|IDNganhNgheKinhDoanhSource", deepLoadType, innerList) 
				&& entity.IDNganhNgheKinhDoanhSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.IDNganhNgheKinhDoanh;
				NganhNgheKinhDoanh tmpEntity = EntityManager.LocateEntity<NganhNgheKinhDoanh>(EntityLocator.ConstructKeyFromPkItems(typeof(NganhNgheKinhDoanh), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.IDNganhNgheKinhDoanhSource = tmpEntity;
				else
					entity.IDNganhNgheKinhDoanhSource = DataRepository.NganhNgheKinhDoanhProvider.GetByIDNganhNgheKinhDoanh(transactionManager, entity.IDNganhNgheKinhDoanh);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IDNganhNgheKinhDoanhSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.IDNganhNgheKinhDoanhSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.NganhNgheKinhDoanhProvider.DeepLoad(transactionManager, entity.IDNganhNgheKinhDoanhSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion IDNganhNgheKinhDoanhSource

			#region IDNhaCungCapSource	
			if (CanDeepLoad(entity, "NhaCungCap|IDNhaCungCapSource", deepLoadType, innerList) 
				&& entity.IDNhaCungCapSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.IDNhaCungCap;
				NhaCungCap tmpEntity = EntityManager.LocateEntity<NhaCungCap>(EntityLocator.ConstructKeyFromPkItems(typeof(NhaCungCap), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.IDNhaCungCapSource = tmpEntity;
				else
					entity.IDNhaCungCapSource = DataRepository.NhaCungCapProvider.GetByIDNhaCungCap(transactionManager, entity.IDNhaCungCap);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IDNhaCungCapSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.IDNhaCungCapSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.NhaCungCapProvider.DeepLoad(transactionManager, entity.IDNhaCungCapSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion IDNhaCungCapSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		internal override bool DeepSave(TransactionManager transactionManager, Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region IDNganhNgheKinhDoanhSource
			if (CanDeepSave(entity, "NganhNgheKinhDoanh|IDNganhNgheKinhDoanhSource", deepSaveType, innerList) 
				&& entity.IDNganhNgheKinhDoanhSource != null)
			{
				DataRepository.NganhNgheKinhDoanhProvider.Save(transactionManager, entity.IDNganhNgheKinhDoanhSource);
				entity.IDNganhNgheKinhDoanh = entity.IDNganhNgheKinhDoanhSource.IDNganhNgheKinhDoanh;
			}
			#endregion 
			
			#region IDNhaCungCapSource
			if (CanDeepSave(entity, "NhaCungCap|IDNhaCungCapSource", deepSaveType, innerList) 
				&& entity.IDNhaCungCapSource != null)
			{
				DataRepository.NhaCungCapProvider.Save(transactionManager, entity.IDNhaCungCapSource);
				entity.IDNhaCungCap = entity.IDNhaCungCapSource.IDNhaCungCap;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<Delegate, object> deepHandles = new Dictionary<Delegate, object>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region NhaCungCapNganhNgheKinhDoanhChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>Indeco.G24.Entities.NhaCungCapNganhNgheKinhDoanh</c>
	///</summary>
	public enum NhaCungCapNganhNgheKinhDoanhChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>NganhNgheKinhDoanh</c> at IDNganhNgheKinhDoanhSource
		///</summary>
		[ChildEntityType(typeof(NganhNgheKinhDoanh))]
		NganhNgheKinhDoanh,
			
		///<summary>
		/// Composite Property for <c>NhaCungCap</c> at IDNhaCungCapSource
		///</summary>
		[ChildEntityType(typeof(NhaCungCap))]
		NhaCungCap,
		}
	
	#endregion NhaCungCapNganhNgheKinhDoanhChildEntityTypes
	
	#region NhaCungCapNganhNgheKinhDoanhFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;NhaCungCapNganhNgheKinhDoanhColumn&gt;"/> class
	/// that is used exclusively with a <see cref="NhaCungCapNganhNgheKinhDoanh"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class NhaCungCapNganhNgheKinhDoanhFilterBuilder : SqlFilterBuilder<NhaCungCapNganhNgheKinhDoanhColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the NhaCungCapNganhNgheKinhDoanhFilterBuilder class.
		/// </summary>
		public NhaCungCapNganhNgheKinhDoanhFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the NhaCungCapNganhNgheKinhDoanhFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public NhaCungCapNganhNgheKinhDoanhFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the NhaCungCapNganhNgheKinhDoanhFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public NhaCungCapNganhNgheKinhDoanhFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion NhaCungCapNganhNgheKinhDoanhFilterBuilder
	
	#region NhaCungCapNganhNgheKinhDoanhParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;NhaCungCapNganhNgheKinhDoanhColumn&gt;"/> class
	/// that is used exclusively with a <see cref="NhaCungCapNganhNgheKinhDoanh"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class NhaCungCapNganhNgheKinhDoanhParameterBuilder : ParameterizedSqlFilterBuilder<NhaCungCapNganhNgheKinhDoanhColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the NhaCungCapNganhNgheKinhDoanhParameterBuilder class.
		/// </summary>
		public NhaCungCapNganhNgheKinhDoanhParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the NhaCungCapNganhNgheKinhDoanhParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public NhaCungCapNganhNgheKinhDoanhParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the NhaCungCapNganhNgheKinhDoanhParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public NhaCungCapNganhNgheKinhDoanhParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion NhaCungCapNganhNgheKinhDoanhParameterBuilder
} // end namespace
